package gov.nist.ssd.swqb.commands;

import gov.nist.ssd.swqb.core.Display;
import gov.nist.ssd.swqb.core.exceptions.OutOfBoundsException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Benjamin Herbomez <benjamin.herbomez@esial.com>
 */
public class ChangeDisplayCount implements Command{

    private Display display;
    private int nextCount;
    private int currentCount;
    private int currentPage;

    public ChangeDisplayCount(Display display, int next) {
        this.display        = display;
        this.nextCount      = next;
        this.currentCount   = display.getDisplayCount();
        this.currentPage    = display.getCurrentPageIndex();
    }
    
    
    @Override
    public void exec() {
        this.display.setDisplayCount(nextCount);
    }

    @Override
    public void unExec() {
        this.display.setDisplayCount(currentCount);
        try {
            this.display.setPageIndex(currentPage);
        } catch (OutOfBoundsException ex) {
            Logger.getLogger(ChangeDisplayCount.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
